package com.lxn.topic;

import com.lxn.ConnectionUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.MessageProperties;

//发送
public class Send {
    //交换机名字
    public static final String NAME_EXCHANGE_TOPIC = "topic";
    public static void main(String[] args) throws Exception {
        //连接工具获取连接对象
        Connection connection = ConnectionUtil.getConnection();
        //创建通道
        Channel channel = connection.createChannel();
        //创建交换机，通配符
        channel.exchangeDeclare(NAME_EXCHANGE_TOPIC, BuiltinExchangeType.TOPIC,true);
        //发消息
        String msg = "topic MQ";
        channel.basicPublish(NAME_EXCHANGE_TOPIC,"user.delete", MessageProperties.PERSISTENT_TEXT_PLAIN,msg.getBytes());
        System.out.println("发送成功!"+msg);

    }

}
